package com.z100h.supplychain.sku.web;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.sys.entity.DictType;
import com.jeeplus.modules.sys.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Sku类目配置
 */
@Controller
@RequestMapping(value = "${adminPath}/sku/category")
public class SkuCategoryController extends BaseController {

    @Autowired
    private DictTypeService dictTypeService;


    @RequestMapping(value = {"thirdCategory", ""})
    public String thirdCategory(HttpServletRequest request) {
        request.setAttribute("category", "sc_category_c");
        return "supplychain/category/category";
    }

    @RequestMapping(value = {"firstCategory", ""})
    public String firstCategory(HttpServletRequest request) {
        request.setAttribute("category", "sc_category_a");
        return "supplychain/category/category";
    }


    @RequestMapping(value = {"secondCategory", ""})
    public String secondCategory(HttpServletRequest request) {
        request.setAttribute("category", "sc_category_b");
        return "supplychain/category/category";
    }

    @ResponseBody
    @RequestMapping(value = "data")
    public Map<String, Object> data(DictType dictType, HttpServletRequest request, HttpServletResponse response, Model model) {
        String category = request.getParameter("category");
        dictType.setType(category);
        Page<DictType> page = dictTypeService.findPage(new Page<DictType>(request, response), dictType);
        return getBootstrapData(page);
    }

    @RequestMapping(value = {"unit", ""})
    public String unit(HttpServletRequest request) {
        request.setAttribute("category", "sc_sku_unit");
        return "supplychain/category/category";
    }
}
